<template>
  <div class="list" style="height:100%">
    <UserIndexTop :showfun="hidden"></UserIndexTop>
    <div class="list-con">
      <div class="list-con-header">
        <div class="list-header-info">
          <div class="list-header-img">
            <div class="list-header-imgcon">
              <div class="list-user">
                <img src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" alt />
              </div>
              <div class="list-header-bt">
                <p>
                  <span>5</span>
                  <span>小程序</span>
                </p>
                <p>
                  <span>5</span>
                  <span>小程序</span>
                </p>
              </div>
            </div>
            <div class="list-user-info">
              <span>门上的三颗心</span>
              <span class="list-user-money">余额：0</span>
              <span class="list-user-center">个人中心 ></span>
            </div>
          </div>
          <div class="list-header-right">
            <span class="user-version">当前版本: 体验版</span>
            <span class="user-up">升级后可以使用更多功能</span>
            <p class="goup">去升级</p>
          </div>
          <div class="list-header-right" style="padding:10px">
            <div class="service-con">
              <div class="header-img">
                <img src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" alt />
              </div>
              <div class="header-bot">
                <span>客服</span>
                <span>套餐咨询</span>
              </div>
            </div>
            <p class="header-online">在线咨询</p>
            <span>客服电话：123-456-7890</span>
          </div>
        </div>
        <div class="list-header-ad">
          <div>
            <svg-icon icon-class="guangbo" />系统公告：
          </div>
          <div>
            <router-link to="#">查看更多>>></router-link>
          </div>
        </div>
      </div>
      <div class="list-con-bt">
        <p>
          <span>站点列表</span>
          <span>模板市场</span>
          <span>交易订单</span>
        </p>
        <p @click="addMyApply">
          <i class="el-icon-plus" />
          {{sort | newSort}}
        </p>
      </div>
      <div class="list-mini">
        <div class="list-mini-item" v-for="(item, idx) in listData" :key="idx">
          <div class="list-mini-item-img">
            <img src="http://gw.alicdn.com/mt/TB1PNLZKXXXXXaTXXXXXXXXXXXX-750-481.jpg" alt />
          </div>
          <div class="list-mini-item-right">
            <div class="list-mini-item-top">
              <p>
                <span class="item-name">{{item.name}}</span>
                <span style="margin-left:15px;margin-top:10px">
                  <img src="@/assets/config_images/xiaochengxu1.png" alt />
                </span>
              </p>
              <span>
                <i class="el-icon-time"></i>
                {{item.create_time}}
              </span>
            </div>
            <div class="list-mini-item-bot">
              <div class="list-bot-item-left">
                <p @click="goDiy(item.id)">编辑小程序</p>
                <p @click="goMangent(item.id)">管理</p>
                <p>预览</p>
                <p @click="goEmpower(item.id)">授权信息</p>
              </div>
              <p class="list-bot-del-btn" @click="delApplyIdx(item.id)">删除小程序</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import UserIndexTop from "@/components/IndexCon/userindextop";
import { getApplyList, delApplyIdx } from "@/api/apply";
export default {
  components: { UserIndexTop },
  data() {
    return {
      hidden: false,
      listData: [],
      sort: 0
    };
  },
  filters: {
    newSort: function(value) {
      switch (value) {
        case "1":
          return "微信小程序";
        case "4":
          return "支付宝小程序";
        case "6":
          return "QQ小程序";
        default:
          break;
      }
    }
  },
  mounted: function() {
    // 拿到应用类型
    this.sort = this.$route.query.type;
    // 加载应用列表
    this.getList();
  },
  methods: {
    addMyApply() {
      if (this.listData.length >= 2) {
        this.$message({
          type: "info",
          message: "每人只能创建一个应用！！"
        });
        return;
      } else {
        this.$router.push("/addpro?type=" + this.$route.query.type);
      }
    },
    getList() {
      getApplyList(1, this.sort).then(res => {
        if (res.code === 200) {
          if (res.data.length > 0) {
            this.listData = res.data;
          }
        }
      });
    },
    // 删除应用
    delApplyIdx(idx) {
      this.$confirm("此操作将永久删除该应用, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          delApplyIdx(idx).then(res => {
            if (res.code === 200) {
              for (const i in this.listData) {
                if (this.listData[i].id === idx) {
                  this.listData.splice(i, 1);
                }
              }
              this.$message({
                type: "success",
                message: "删除成功!"
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    goDiy(idx) {
      this.$store.commit("apply/SET_ApplyID", idx);
      this.$router.push({
        path: "/diymodule?applyId=" + idx
      });
    },
    goMangent(id) {
      // this.$router.push({
      //   path: "/dashboard"
      // });
      // 限制

      var token = this.$store.state.user.token;
      location.href = "http://cs1.58zltc.com?token=" + token + "&id=" + id;
    },
    goEmpower(id) {
      this.$router.push({
        path: "/empower",
        query: {
          appid: id
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.list {
  background: rgba(242, 243, 245, 1);
}
.list-con {
  width: 1024px;
  min-width: 1024px;
  height: auto;
  margin: 100px auto 0;
  .list-con-header {
    width: 100%;
    height: 255px;
    padding: 19px 21px;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 2px 5px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(223, 223, 223, 1);
    .list-header-info {
      display: flex;
      height: 190px;
      border-bottom: 1px solid rgba(223, 223, 223, 1);
      .list-header-img {
        width: 56%;
        display: flex;
        border-right: 1px solid #dfdfdf;
        .list-user {
          width: 122px;
          height: 122px;
          border-radius: 61px;
          overflow: hidden;
          margin-left: 12px;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }

      .list-user-info {
        padding-top: 20px;
        height: 120px;
        display: flex;
        margin-left: 30px;
        color: #353535;
        font-size: 23px;
        flex-direction: column;
        justify-content: space-around;
        .list-user-money {
          font-size: 16px;
          color: #a2a2a2;
        }
        .list-user-center {
          width: 90px;
          height: 28px;
          line-height: 28px;
          text-align: center;
          font-size: 14px;
          color: #79b0ff;
          border-radius: 2px;
          border: 1px solid rgba(121, 176, 255, 1);
          cursor: pointer;
        }
      }
      .list-header-right {
        width: 22%;
        display: flex;
        padding: 16px 20px 0;
        flex-direction: column;
        border-right: 1px solid #dfdfdf;
        justify-content: space-between;
        cursor: pointer;
        .user-version {
          font-size: 16px;
          font-weight: 500;
          color: rgba(53, 53, 53, 1);
          line-height: 16px;
        }
        .user-up {
          font-size: 14px;
          color: #888888;
        }
        .goup {
          width: 64px;
          height: 28px;
          margin-top: 10px;
          color: #ffffff;
          font-size: 14px;
          line-height: 28px;
          text-align: center;
          background: #79b0ff;
        }
        .service-con {
          width: 100%;
          display: flex;
          .header-img {
            width: 48px;
            height: 48px;
            border-radius: 24px;
            overflow: hidden;
            img {
              width: 100%;
              height: 100%;
            }
          }
          .header-bot {
            height: 40px;
            font-size: 16px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            margin-left: 10px;
          }
        }
        .header-online {
          width: 170px;
          height: 34px;
          border-radius: 2px;
          border: 1px solid rgba(121, 176, 255, 1);
          font-size: 14px;
          font-weight: 500;
          color: rgba(121, 176, 255, 1);
          line-height: 34px;
          text-align: center;
          cursor: pointer;
        }
      }
      .list-header-right:nth-child(3) {
        border: none;
      }
    }
    .list-header-ad {
      width: 100%;
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }
  .list-header-bt {
    width: 158px;
    height: 50px;
    display: flex;
    justify-content: space-between;
    p {
      width: 50%;
      height: 48px;
      display: flex;
      border-right: 1px solid #dfdfdf;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
    }
    p:nth-child(2) {
      border: none;
    }
  }
  .list-con-bt {
    height: 50px;
    color: #888888;
    font-size: 18px;
    display: flex;
    padding: 0 10px;
    justify-content: space-between;
    p:nth-child(2) {
      width: 100px;
      height: 34px;
      font-size: 14px;
      color: #ffffff;
      text-align: center;
      line-height: 34px;
      background: rgba(121, 176, 255, 1);
      box-shadow: 0px 4px 9px 2px rgba(121, 176, 255, 0.4);
      border-radius: 3px;
      cursor: pointer;
    }
  }
  .list-mini {
    width: 100%;
    height: auto;
    margin-top: 10px;
    .list-mini-item {
      height: 150px;
      display: flex;
      padding: 19px 21px;
      margin-top: 15px;
      background: rgba(255, 255, 255, 1);
      box-shadow: 0px 2px 5px -1px rgba(0, 0, 0, 0.2);
      .list-mini-item-img {
        width: 116px;
        height: 116px;
        border-radius: 6px;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
    .list-mini-item-right {
      width: 90%;
      .list-mini-item-top {
        height: 50px;
        display: flex;
        padding-left: 20px;
        align-items: center;
        justify-content: space-between;
        .item-name {
          font-size: 23px;
          color: #353535;
          font-weight: 500;
          line-height: 22px;
        }
      }
      .list-bot-item-left {
        width: 350px;
        display: flex;
        justify-content: space-between;
        p {
          width: auto;
          height: 30px;
          line-height: 30px;
          color: #79b0ff;
          /* padding: 6px; */
          padding: 0 10px;
          text-align: center;
          line-height: 30px;
          border: 1px solid #79b0ff;
        }
        p:hover {
          color: #ffffff;
          background: rgba(121, 176, 255, 1);
          cursor: pointer;
        }
      }
      .list-bot-del-btn {
        width: 116px;
        line-height: 19px;
        text-align: center;
        padding: 9px 13px;
        color: #888888;
        border-radius: 2px;
        border: 1px solid rgba(223, 223, 223, 1);
        cursor: pointer;
      }
      .list-mini-item-bot {
        width: 100%;
        padding-left: 20px;
        display: flex;
        justify-content: space-between;
      }
    }
  }
}
</style>
